home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / open,open ƒ / open,open.c next >
Encoding:
C/C++ Source or Header  |  1992-06-07  |  3.4 KB  |  159 lines  |  [TEXT/KAHL]

  1. /* open,open.c -
  2. /*     going-away present for our good,good friend Lynn Civello, also */
  3. /*  known as Lynnis, who is going off to charm Massachusetts. */
  4. /*  causes a recording of Lynn saying "open,open,open" to play at */
  5. /*  each launch */
  6. /* © copyright 1992, Eric Slosser, all rights reserved */
  7.  
  8. #include <SetupA4.h>
  9. #include <Sound.h>
  10. #include <Traps.h>
  11. #include <Processes.h>
  12.  
  13. pascal extern void SHOWINIT(short iconID, short moveX);
  14.  
  15. typedef pascal short (*TrackType) (ControlHandle,Point,ProcPtr);
  16. typedef pascal short (*LaunchType) (LaunchParamBlockRec *params);
  17.  
  18. TrackType    gOldTrackControl;
  19. LaunchType    gOldLaunch;
  20. long        gOldMenuDispatch;
  21.  
  22. long        gDirID;
  23. short        gVRefNum;
  24. Str31        gName;
  25.  
  26. Str15    kOpen    =    "\pOpen";
  27.  
  28. /*------------------------------*/
  29. pascal short myTrackControl( ControlHandle ctl, Point p, ProcPtr action );
  30. pascal short myLaunch( LaunchParamBlockRec *params );
  31. pascal short myMenuDispatch( short selector );
  32. int             pstrcmp ( StringPtr s, StringPtr t );
  33.  
  34. /*------------------------------*/
  35. void    PlaySound(void);
  36. void    PlaySound(void)
  37. {
  38.     short    saved,resRef;
  39.     Handle    soundH;
  40.     
  41.     saved = CurResFile();
  42.     resRef = HOpenResFile( gVRefNum, gDirID, gName, fsRdPerm);
  43.     if ( resRef>0 ) {
  44.         UseResFile(resRef);
  45.         if (soundH = GetResource('snd ',128)) {
  46.             DetachResource(soundH);
  47.             SndPlay(nil,soundH,true);
  48.             }
  49.         CloseResFile(resRef);
  50.         UseResFile(saved);
  51.         }
  52. }
  53. /*------------------------------*/
  54. pascal short myTrackControl( 
  55.     ControlHandle    ctl,
  56.     Point            p,
  57.     ProcPtr            action )
  58. {
  59.     short    part;
  60.     unsigned char *cTitle;
  61.     
  62.     SetUpA4();
  63.     part = (*gOldTrackControl)( ctl,p,action ); /* can you say "tail patch"? */
  64.     if ( part==inButton ) {
  65.         cTitle = (**ctl).contrlTitle;
  66.         if (!pstrcmp(cTitle,kOpen) )
  67.             PlaySound();
  68.         }
  69.     RestoreA4();
  70.     return(part);
  71. }    /* myTrackControl */
  72. /*------------------------------*/
  73. pascal short myLaunch( 
  74.     LaunchParamBlockRec *params )
  75. {
  76.     SetUpA4();
  77.     PlaySound();
  78.     gOldLaunch(params);
  79.     RestoreA4();
  80. }    /* myLaunch */
  81. /*------------------------------*/
  82. pascal short myMenuDispatch( short selector )
  83. {
  84.     SetUpA4();
  85.     if ( selector==1 )
  86.         PlaySound();
  87.     asm { 
  88.         move.l     gOldMenuDispatch,a0
  89.         move.l    (sp)+,a4    /* RestoreA4 */
  90.         unlk    a6
  91.         jmp        (a0)
  92.         }
  93. }    /* myLaunch */
  94. /*------------------------------*/
  95. void    SaveResFileInfo(void);
  96. void    SaveResFileInfo(void)
  97. {
  98.     Handle    h;
  99.     short    resRef;
  100.     FCBPBRec pb;
  101.     
  102.     asm { 
  103.         RecoverHandle
  104.         move.l    a0,h
  105.         }
  106.  
  107.     resRef = HomeResFile(h);
  108.     DetachResource(h);
  109.     
  110.     pb.ioFCBIndx = 0;
  111.     pb.ioFCBIndx = 0;
  112.     pb.ioNamePtr = gName;
  113.     pb.ioRefNum = resRef;
  114.     PBGetFCBInfo(&pb,false);
  115.     
  116.     gVRefNum = pb.ioFCBVRefNum;
  117.     gDirID = pb.ioFCBParID;
  118. }
  119. /*------------------------------*/
  120. int        pstrcmp ( StringPtr s, StringPtr t )
  121. {
  122.     register int    i;
  123.     
  124.     if ( *s != *t )
  125.         return ( *s - *t );    /* >0 if s is longer, <0 is t is longer */
  126.         
  127.     for ( i=*s; *s==*t && i>=0; s++,t++,i-- )
  128.         ;
  129.     
  130.     if ( i<0 ) 
  131.         return( 0 );
  132.     else
  133.         return ( *s - *t );
  134. }
  135. /*------------------------------*/
  136. main()
  137. {
  138. #define _MenuDispatch 0xa825
  139.     RememberA0();
  140.     SetUpA4();
  141.     
  142.     
  143.     SaveResFileInfo();
  144.     
  145.     gOldTrackControl = (TrackType) NGetTrapAddress(_TrackControl,ToolTrap);
  146.     NSetTrapAddress( (long) myTrackControl,_TrackControl,ToolTrap);
  147.  
  148.     gOldLaunch = (LaunchType) NGetTrapAddress(_Launch,ToolTrap);
  149.     NSetTrapAddress( (long) myLaunch,_Launch,ToolTrap);
  150.  
  151.     gOldMenuDispatch = NGetTrapAddress(_MenuDispatch,ToolTrap);
  152.     NSetTrapAddress( (long) myMenuDispatch,_MenuDispatch,ToolTrap);
  153.  
  154.     SHOWINIT(128,-1);
  155.  
  156.     RestoreA4();
  157. }
  158. /*------------------------------*/
  159.